﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using LINQSamples.Data;

namespace Web.Samples
{
    public partial class SelectFilterDrill : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindQuery();
            this.BindImperative();
        }

        private void BindQuery()
        {
            var query = from p in Product.GetProducts()
                        where p.Color == "Black" && p.ProductDocuments.Count > 0
                        select p;

            foreach (Product p in query)
            {
                this.litImperativeResults.Text += "<strong>" + p.Name + "</strong><br />\n";
                this.litImperativeResults.Text += string.Format("<div style=\"padding-left: 10px;\">");
                foreach (var ob in p.ProductDocuments)
                {
                    this.litImperativeResults.Text += "Document ID: " + ob.DocumentID + "<br />\n";
                }
                this.litImperativeResults.Text += "</div>";
            }
        }

        private void BindImperative()
        {
            var query = Product.GetProducts().Where(p => p.Color == "Black" && p.ProductDocuments.Count > 0);

            foreach (Product p in query)
            {
                this.litQueryResults.Text += "<strong>" + p.Name + "</strong><br />\n";
                this.litQueryResults.Text += string.Format("<div style=\"padding-left: 10px;\">");
                foreach (var ob in p.ProductDocuments)
                {
                    this.litQueryResults.Text += "Document ID: " + ob.DocumentID + "<br />\n";
                }
                this.litQueryResults.Text += "</div>";
            }
        }
    }
}
